package com.engr.lyx.common.oauth2;

import com.engr.lyx.common.utils.ResponseMapUtils;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: blog
 * @desc: oauth2 未授权异常处理
 * @author: lyx
 * @date: 2019-01-18 14:03
 **/
@Component
public class CustomAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException, ServletException {

        ResponseMapUtils.responseMapMessage(request, response, HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
    }
}
